import { FormSchema } from '/@/components/Table';
import { getDictTypeListApi } from '/@/api/admin/dict';
import { DICT } from '/@/enums/dict';
import editorStore from '/@/store/modules/bpmnEditor';
import modelerStore from '/@/store/modules/bpmnModeler';
const editor = editorStore();
const modeler = modelerStore();
import { nextTick } from 'vue';

// const templateTypeOptions = [
//   { label: '普通模板', value: 0 },
//   { label: 'pc端模板', value: 1 },
//   { label: '移动端模板', value: 2 },
// ];
const flowFlagOptions = [
  { label: '自由流转规则', value: 1 },
  { label: '顺序规则', value: 2 },
  { label: '结构处理方式', value: 4 },
];
const configTransferOptions = [
  { label: '不可以传阅', value: 0 },
  { label: '可以传阅', value: 1 },
  { label: '部门内部传阅', value: 2 },
];
const pageTypeOptions = [
  { label: '不分页显示', value: 0 },
  { label: '分页显示', value: 1 },
  { label: '正文附件分页', value: 2 },
];
const isPublicUsingOptions = [
  { label: '不可使用', value: 0 },
  { label: '管理', value: 1 },
  { label: '应用', value: 2 },
  { label: '新建', value: 3 },
];
const firstTypeOptions = [
  { label: '正文', value: 0 },
  { label: '附件', value: 1 },
];

export const basicInfoFormSchema: FormSchema[] = [
  {
    field: 'theme',
    label: '设计器主题',
    required: true,
    component: 'ApiSelect',
    defaultValue: 1,
    colProps: { span: 24 },
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.BPMN_THEME,
      },
      onChange: (e) => {
        // console.log('%c=====设计器主题', 'color:#7ea;font-size:30px;font-weight:bold', e);

        nextTick(async () => {
          const modelerItem = modeler.getModeler!;

          const { xml } = await modelerItem.saveXML({ format: true, preamble: true });

          editor.updateBpmnContent(xml as string);
          editor.updateTheme(e);
        });
      },
    },
  },
  {
    field: 'name',
    label: '模板名称',
    required: true,
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'code',
    label: '模板代码',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'orderId',
    label: '排列顺序',
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'templateType',
    label: '模板类型',
    component: 'ApiSelect',
    required: true,
    colProps: { span: 24 },
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.TEMPLATE_TYPE,
      },
    },
  },
  {
    field: 'flowFlag',
    label: '流转类型',
    component: 'Select',
    colProps: { span: 24 },
    required: true,
    componentProps: {
      options: flowFlagOptions,
    },
  },
  {
    field: 'reminderInterval',
    label: '催办触发阈值',
    required: true,
    component: 'InputNumber',
    colProps: { span: 24 },
  },
  {
    field: 'verifySignatureUrl',
    label: '签名URL',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'notifyFinishedFlag',
    label: '结束后发送通知',
    component: 'Select',
    defaultValue: 0,
    componentProps: {
      options: [
        {
          label: '通知',
          value: 1,
        },
        {
          label: '不通知',
          value: 0,
        },
      ],
    },
    colProps: { span: 24 },
  },

  {
    field: 'configTransfer',
    label: '传阅类型',
    component: 'Select',
    colProps: { span: 24 },
    required: true,
    componentProps: {
      options: configTransferOptions,
    },
  },

  {
    field: 'pageType',
    label: '分页类型',
    component: 'Select',
    colProps: { span: 24 },
    componentProps: {
      options: pageTypeOptions,
    },
  },
  {
    field: 'isPublicUsing',
    label: '模板使用类型',
    component: 'Select',
    colProps: { span: 24 },
    componentProps: {
      options: isPublicUsingOptions,
    },
  },
  {
    field: 'firstType',
    label: '首页显示内容',
    component: 'Select',
    colProps: { span: 24 },
    componentProps: {
      options: firstTypeOptions,
    },
  },
  {
    field: 'msgClassify',
    label: '二级消息分类',
    component: 'ApiSelect',
    colProps: { span: 24 },
    componentProps: {
      api: getDictTypeListApi,
      labelField: 'label',
      valueField: 'intValue',
      params: {
        type: DICT.MSG_CLASSIFY,
      },
    },
  },
  {
    field: 'summary',
    label: '说明',
    component: 'InputTextArea',
    colProps: { span: 24 },
  },

  {
    field: 'author',
    label: '创建人',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'createDate',
    component: 'DatePicker',
    label: '创建时间',
    colProps: {
      span: 24,
    },
  },
  {
    field: 'editor',
    label: '修改人',
    component: 'Input',
    colProps: { span: 24 },
  },
  {
    field: 'editDate',
    component: 'DatePicker',
    label: '修改时间',
    colProps: {
      span: 24,
    },
  },
];
